package com.acme.bankapp.service.networking;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author Gregory Sobko
 */
public class BankServer{
    private final int portNumber;

    public BankServer(int portNumber) {
        this.portNumber = portNumber;
    }

    public void runServer(ServerWorker worker){
        try(ServerSocket acceptor = new ServerSocket(portNumber);
            Socket socket = acceptor.accept();
            InputStream inputStream = socket.getInputStream();
            OutputStream outputStream = socket.getOutputStream()
        ){
            worker.doWork(inputStream,outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
